AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

local Energy_Increment = 20

function ENT:Initialize()
	self.BaseClass.Initialize(self)
	self.damaged = 0
	if not (WireAddon == nil) then
		self.WireDebugName = self.PrintName
		self.Outputs = Wire_CreateOutputs(self.Entity, { "Out" })
	end
end

function ENT:TurnOn()
	if (self.Active == 0) then
		self.Active = 1
		self:SetOOO(1)
	end
end

function ENT:TurnOff()
	if (self.Active == 1) then
		self.Active = 0
		self:SetOOO(0)
		if not (WireAddon == nil) then Wire_TriggerOutput(self.Entity, "Out", 0) end
	end
end

function ENT:SetActive() --disable use, lol
end

function ENT:Damage()
	if (self.damaged == 0) then self.damaged = 1 end
end

function ENT:Repair()
	self.BaseClass.Repair(self)
	self.Entity:SetColor(255, 255, 255, 255)
	self.damaged = 0
end

function ENT:Destruct()
	if CAF and CAF.GetAddon("Life Support") then
		CAF.GetAddon("Life Support").Destruct( self.Entity, true )
	end
end

function ENT:Extract_Hops()
	local RD = CAF.GetAddon("Resource Distribution")
	local inc = 0
	if GAMEMODE.IsSpacebuildDerived then
		if not self.environment then return end
		inc = math.ceil(Energy_Increment / ((self.environment:GetAtmosphere()) + 1))
	else
		inc = math.ceil(Energy_Increment / 2)
	end
	if (self.damaged == 1) then inc = math.ceil(inc / 2) end
	if (inc > 0) then
		inc = math.ceil(inc * self:GetMultiplier())
		RD.SupplyResource(self, "unprocessed hops", inc)
	end
	if not (WireAddon == nil) then Wire_TriggerOutput(self.Entity, "Out", inc) end
end

function ENT:Think()
	self.BaseClass.Think(self)
	self:Extract_Hops()
	self.Entity:NextThink(CurTime() + 1)
	return true
end
